﻿#include "Common.h"

// 移除非双引号和<>之间的空格和换行
std::string RemoveSpaceAndEnter(const char * pSrc)
{
    try
    {
        if (NULL == pSrc)
        {
            return std::string("");
        }
        int nQuotCnt = 0;       // 双引号个数
        int nClose = 0;         // <>是否成对
        std::string strResult;
        // 移除非双引号之间的空格和换行，‘<’和‘>’之间的空格也不能去掉
        for (unsigned int i = 0; pSrc[i]; i++)
        {
            if (pSrc[i] == '\"')
            {
                nQuotCnt++;
            }
            else if (pSrc[i] == '<')
            {
                nClose++;
            }
            else if (pSrc[i] == '>')
            {
                nClose--;
            }
            if ((nQuotCnt % 2 == 0) && nClose == 0 && (pSrc[i] == ' ' || pSrc[i] == '\r' || pSrc[i] == '\n'))
            {
                continue;
            }
            strResult += pSrc[i];
        }
        return strResult;
    }
    catch (const std::exception&) {}
    return std::string(pSrc);
}
